import api from '../../api/index.js'
import config from '../../common/config.js'
const authorize = {
	state: {
		showLg: false,
		showPhone: false
	},
	mutations: {
		get_show(state) {
			let userInfo = uni.getStorageSync('userInfo');
			let phone = uni.getStorageSync('phone');
			state.showLg = userInfo.nickName? false: true;
			if(userInfo.nickName) {
				// state.showLg = false;
				state.showPhone = phone? false: true;
				console.log('11 ==>',state.showLg,state.showPhone)
			}
		},
		set_show(state) {
			state.showPhone = state.showLg = false;
			console.log('22 ==>',state.showLg,state.showPhone)
		}
	},
	actions: {
		//获取SessionKey
		get_SessionKey({state},opt) {
			return api.getSessionKey(opt)
		},
		//登录
		LONGIN({state},opt) {
			return	new Promise((resolve, reject)=>{
				uni.request({
					url: `${config.url_config}/blade-auth/oauth/token?tenantId=${opt.tenantId}&username=${opt.username}&password=${opt.password}&grant_type=${opt.grant_type}&scope=${opt.scope}&type=${opt.type}&User_Type=${opt.User_Type}&WX_Code=${opt.WX_Code}`,
					method: 'POST',
					header: {
						'content-type': 'application/json',
						'Authorization':'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
						'Tenant-Id':opt.tenantId,
					},
					success: (res) => {
						console.log('res ==>', res)
						if (res.data && res.statusCode == 200) {
							resolve(res)
						} else {
							resolve(res)
						}
					},
					fail: (err) => {
						reject(err)
					}
				})
			})
		},
	}
}

export default authorize